package com.plsjavaweb.dao.utilities;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.apache.log4j.Logger;

import com.plsjavaweb.dao.DAOFactory;
import com.plsjavaweb.logging.LoggingConstants;


public class ConnectionFactory {
	static Logger log= Logger.getLogger(DAOFactory.class);
	static LoggingConstants logConst = new LoggingConstants();
	
	public static Connection getConnection() throws SQLException, NamingException{
		log.info(logConst.entryMessage);
	
		Context ctx = new InitialContext();
		DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myPool");
		Connection conn = ds.getConnection();
		
		log.info(logConst.returnedMessage);
		return conn;
	}
}
